
#include <stdint.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/types.h>
#include "autoconfig.h"
#include "sys/err.h"
#include "lcd_api.h"
#include "apitrans.h"

extern sys_apitrans_t sysapi;


int lcd_set_attribute(uint8_t atr, void * arg)
{
    int (*plcd_set_attribute)(uint8_t atr, void * arg);
    
    plcd_set_attribute = sysapi(LCD_SET_ATTRI_API);
    if (plcd_set_attribute) {
        return plcd_set_attribute(atr, arg);
    }
    return -API_UNSUPPORTED_ERR;
}

void lcd_backlight(uint32_t on)
{
    lcd_set_attribute(LCD_ATTR_BACKLIGHT, on);
}

void lcd_clrscr(void)
{
    void (*plcd_clrscr)(void);
    
    plcd_clrscr = sysapi(LCD_CLRSCR_API);
    if (plcd_clrscr) {
        plcd_clrscr();
    }
}
int lcd_disp_img(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t * img)
{
    int (*plcd_disp_img)(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint8_t * img);
    
    plcd_disp_img = sysapi(LCD_DISP_IMG_API);
    if (plcd_disp_img) {
        return plcd_disp_img(x, y, w, h, img);
    }   
    return -API_UNSUPPORTED_ERR;
}

int lcd_disp_string(uint32_t x, uint32_t y, char * string)
{
    int (*plcd_disp_string)(uint32_t x, uint32_t y, char * string);
    plcd_disp_string = sysapi(LCD_DISP_STRING_API);
    if (plcd_disp_string) {
        return plcd_disp_string(x, y, string);
    }   
    return -API_UNSUPPORTED_ERR;
}

int lcd_disp_hline(uint32_t x, uint32_t y, uint32_t w)
{
    int (*plcd_disp_hline)(uint32_t x, uint32_t y, uint32_t w);
    plcd_disp_hline = sysapi(LCD_DISP_HLINE_API);
    if (plcd_disp_hline) {
        return plcd_disp_hline(x, y, w);
    }   
    return -API_UNSUPPORTED_ERR;
}
int lcd_disp_vline(uint32_t x, uint32_t y, uint32_t h)
{
    int (*plcd_disp_vline)(uint32_t x, uint32_t y, uint32_t h);
    plcd_disp_vline = sysapi(LCD_DISP_VLINE_API);
    if (plcd_disp_vline) {
        return plcd_disp_vline(x, y, h);
    }   
    return -API_UNSUPPORTED_ERR;
}

int lcd_get_type(void)
{
    int (*plcd_get_type)(void);
    plcd_get_type = sysapi(LCD_GET_TYPE_API);
    if (plcd_get_type) {
        return plcd_get_type();
    }   
    return -API_UNSUPPORTED_ERR;
}


int lcd_set_font(lcd_font_type_em emtype)
{
    int (*plcd_set_font)(lcd_font_type_em emtype);
    plcd_set_font = sysapi(LCD_SET_FONT_API);
    if (plcd_set_font) {
        return plcd_set_font(emtype);
    }   
    return -API_UNSUPPORTED_ERR;
}

int lcd_set_space(uint32_t wspace, uint32_t hspace)
{
    int (*plcd_set_space)(uint32_t wspace, uint32_t hspace);
    
    plcd_set_space = sysapi(LCD_SET_SPACE_API);
    if (plcd_set_space) {
        return plcd_set_space(wspace, hspace);
    }   
    return -API_UNSUPPORTED_ERR;
}

int lcd_get_size(uint32_t * pwidth, uint32_t * pheight)
{
    int (*plcd_get_size)(uint32_t * pwidth, uint32_t * pheight);
    
    plcd_get_size = sysapi(LCD_GET_SIZE_API);
    if (plcd_get_size) {
        return plcd_get_size(pwidth, pheight);
    }   
    return -API_UNSUPPORTED_ERR;

}
int kb_get_str(char * input, int in_len, 
                    int min_len, int max_len, 
                    int timeout, char show, int mode)
{
    int (*pkb_get_str)(char * input, int in_len, 
                        int min_len, int max_len, 
                        int timeout, char show, int mode);
    pkb_get_str = sysapi(KB_GET_STR_API);
    if (pkb_get_str) {
        return pkb_get_str(input, in_len, min_len, 
                                max_len, timeout, show, mode);
    }   
    return -API_UNSUPPORTED_ERR;

}

int kb_get_amount(char * amount, int max_len, int timeout)
{
    
    int (*pkb_get_amount)(char * amount, int max_len, int timeout);
    pkb_get_amount = sysapi(KB_GET_AMOUNT_API);
    if (pkb_get_amount) {
        return kb_get_amount(amount, max_len, timeout);
    }   
    return -API_UNSUPPORTED_ERR;
}

int lcd_goto_xy(uint32_t x, uint32_t y)
{
    int (*plcd_goto_xy)(uint32_t x, uint32_t y);
    plcd_goto_xy = sysapi(LCD_GOTO_XY_API);
    if (plcd_goto_xy) {
        return plcd_goto_xy(x, y);
    }   
    return -API_UNSUPPORTED_ERR;

}


int lcd_set_font_color(uint16_t color, font_color_em emtype)
{
    int (*plcd_set_font_color)(uint16_t color, font_color_em emtype);
    plcd_set_font_color = sysapi(LCD_SET_FONT_COLOR_API);
    if (plcd_set_font_color) {
        return plcd_set_font_color(color, emtype);
    }   
    return -API_UNSUPPORTED_ERR;


}

